import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login.vue'),
    },
    
    {
      path: '/main',
      name: 'main',
      component: () => import('../views/Main.vue'),
      meta: { title: '总系统' },
      redirect: '/index',
      children: [
        {
          path: '/printorder',
          name: 'printorder',
          component: () => import('../components/PrintOrder.vue'),
        },
        {
          path: '/index',
          name: 'index',
          component: () => import('../views/main/Index.vue'),
          meta: { title: '首页' }
        },
        
        {
          path: '/account', meta: { title: "系统管理" },
          children: [
            {
              path: '/account',
              name: 'account',
              component: () => import('../views/main/AccountPage.vue'),
              meta: { title: '账号管理' }
            },
            {
              path: '/role',
              name: 'role',
              component: () => import('../views/main/RolePage.vue'),
              meta: { title: '角色管理' }
            },
            {
              path: '/author',
              name: 'author',
              component: () => import('../views/main/AuthorPage.vue'),
              meta: { title: '权限管理' }
            },
          ]
        },
        {
          path: '/advertisement',
          name: 'advertisement',
          component: () => import('../views/main/AdvertisementPage.vue'),
          meta: { title: '广告管理' }
        },
        {
          path: '/news',
          name: 'news',
          component: () => import('../views/main/NewsPage.vue'),
          meta: { title: '新闻管理' }
        },
        {
          path: '/video',
          name: 'video',
          component: () => import('../views/main/VideoPage.vue'),
          meta: { title: '视频管理' }
        },
        {
          path: "/placeOrder", meta: { title: "汽修管理" },
          children: [
            {
              path: '/placeOrder',
              name: 'placeOrder',
              component: () => import('../views/main/PlaceOrderPage.vue'),
              meta: { title: '下单' }
            },
            {
              path: '/veReOrder',
              name: 'veReOrder',
              component: () => import('../views/main/VehicleRepairOrderPage.vue'),
              meta: { title: '订单管理' }
            },
          ]
        },

        {
          path: '/category', meta: { title: "商品管理" },
          children: [
            {
              path: '/category',
              name: 'category',
              component: () => import('../views/main/CategoryPage.vue'),
              meta: { title: '分类管理' }
            },
            {
              path: '/product',
              name: 'product',
              component: () => import('../views/main/ProductPage.vue'),
              meta: { title: '商品列表' }
            },
            {
              path: '/sku',
              name: 'sku',
              component: () => import('../views/main/SkuPage.vue'),
              meta: { title: '设置sku' }
            },
            {
              path: '/productOrder',
              name: 'productOrder',
              component: () => import('../views/main/ProductOrderPage.vue'),
              meta: { title: '订单管理' }
            },
          ]
        },
        {
          path: "/user", meta: { title: "用户管理" },
          children: [
            {
              path: '/user',
              name: 'user',
              component: () => import('../views/main/UserPage.vue'),
              meta: { title: '用户管理' }
            },
            {
              path: '/pointList',
              name: 'pointList',
              component: () => import('../views/main/PointListPage.vue'),
              meta: { title: '积分列表' }
            },
          ]
        },
        {
          path: "/conversations", meta: { title: "客服咨询" },
          children: [
            {
              path: '/conversations',
              name: 'conversations',
              component: () => import('../views/main/conversations.vue'),
              meta: { title: '客服咨询' },
              children: [
                {
                  path: '/conversations/chat/:id', name: 'chat', component: () => import('../views/main/Chat.vue'),
                  meta: { title: "聊天" }
                },
              ]
            }
          ]
        }
      ]
    },
  ],
})
// router.beforeEach((to, from) => {
//   if (!localStorage.getItem('token') && to.path !== '/login') {
//     return '/login'
//   }
//   if (localStorage.getItem('token') && to.path === '/login') {
//     return '/index'
//   }
// })
export default router
